#!/usr/bin/python
# -*- coding: utf-8 -*-
import itchat, time, sys
from itchat.content import *
from util import log, download
from config import debug


@itchat.msg_register(TEXT, isGroupChat=False)
def text_reply(msg):
    if msg.fromUserName == my_id:
        if msg.text == 'do':
            itchat.send_file(download(), toUserName='filehelper')
        else:
            itchat.send('Alive', toUserName='filehelper')


@itchat.msg_register([TEXT, SHARING], isGroupChat=True)
def group_record(msg):
    chatroom_id = msg.fromUserName
    if chatroom_id in chatroom_ids or chatroom_id == my_id:
        return
    log(msg)


if __name__ == '__main__':
    itchat.auto_login(hotReload=False, enableCmdQR=debug + 1)
    my_id = itchat.get_friends()[0].userName
    chatrooms = itchat.get_chatrooms(update=True, contactOnly=True)
    chatroom_ids = [c['UserName'] for c in chatrooms]
    itchat.run(debug=debug)
